{% extends base %}

{% block head %}
<script type="text/javascript" src="/static/lib/csv.js/csv.js"></script>
<script type="text/javascript" src="/static/lib/marked/marked.js"></script>
<script type="text/javascript" src="/static/js/marked-ext.js"></script>
<style>
.CodeMirror {
    width: 60rem;
    font-size:16px;
    height: auto;
}

#markdown-input {
    font-family: monospace;
}

.small {
    font-size: small;
}

.alert {
    color: red;
    background-color: #FFCCCC;
    width: initial;
}

.x-code-block {
    font-family: Consolas,monospace;
    word-wrap: break-word;
    border-style: solid;
    border-radius: 3px;
    border-width: 1px;
    padding: 3px;
    background-color: #ffffcc;
}

.bottom-fixed-pannel {
    background-color: white; 
    position: fixed; 
    padding-bottom: 5px; 
    padding-top:5px; 
    bottom: 0px; 
    z-index: 100
}

.pathlist {
    background-color: #eee;
    padding:3px;
    box-sizing: border-box;
}

.hover {
    color: #AAA;
}

.hover:hover {
    color: #000;
}

.no-border tr td {
    border: none;
}

#uploadIframe {
    border: none;
    width: 100%;
    height: 60px;
}

#markdown-output-div img {
    max-height: 600px;
}

.red-border {
    border-color: red;
}

/** 分组的标签 **/
.group-tag {
    border: 1px solid #ccc;
    background-color: #69c;
    padding: 5px;
    margin: 5px;
    display: block;
    float: left;
    line-height: 20px;
    color: #fff;
}

{% init show_left = False %}
{% if show_left %}
    .x-left {
        position: absolute;
        left: 200px;
        width: 200px;
        bottom: 0px;
        top: 0px;
        overflow-y: auto;
        border-right: 1px solid #ccc;
    }

    .x-left-title {
        border-bottom: 1px solid #ccc;
        padding: 5px;
    }

    .x-left-content {
        padding: 5px;
    }

    .x-left-content li {
        list-style: none;
        line-height: 20px;
        padding-bottom: 5px;
    }

    .x-body {
        left: 400px;
    }
{% end %}

</style>
{% end %}

{% block left_part %}
    {% init groups = [] %}
    {% init show_groups = False %}
    {% init dir_type = "" %}
    {% init tags = "" %}

    {% if show_groups %}
        <div class="x-left-title">
            目录
            {% if _has_login %}
                <a class="float-right" href="/note/add?parent_id={{file.parent_id}}">{{T("Create")}}</a>
            {% end %}
        </div>
        <div class="x-left-content">
            {% if _has_login %}
                <li>
                    <i class="fa fa-chevron-left"></i>
                    <a class="link" href="/note/books">返回书架</a>
                </li>
            {% end %}
            
            {% for item in groups %}
                <li>
                    {% if item.type == "group" %}
                        <i class="fa fa-folder orange"></i>
                    {% elif item.type == "gallery" %}
                        <i class="fa fa-photo"></i>
                    {% elif item.type == "csv" %}
                        <i class="fa fa-table"></i>
                    {% else %}
                        <i class="fa fa-file-text-o"></i>
                    {% end %}

                    {%if item.priority>0%}
                        <i class="fa fa-thumb-tack black"></i>
                    {%end%}
                    <a class="link" href="/note/{{item.id}}?dir_type={{dir_type}}&tags={{tags}}">
                        {{item.name}}
                    </a>
                </li>
            {% end %}
        </div>
    {% end %}
{% end %}

{% block body %}
    {% init file_type       = "md" %}
    {% init pathlist        = [] %}
    {% init file            = None %}
    {% init show_notice     = False %}
    {% init show_search_div = True %}
    {% init show_add_file   = False %}
    {% init show_add_group  = False %}
    {% init show_path_list  = True %}
    {% init show_pagination = True %}
    {% init error           = "" %}

    {% if file != None %}
        {% set globals()['file_type'] = file.type %}
        {% set globals()['file_id'] = file.id %}
    {% end %}

    {# 收藏一下这个符号 › #}
    <div class="col-md-12 card">
        {% comment 如果有新类型的文件，继续增加file_type即可，后台实现不用变更 %}
        {% if file_type == "group" %}
            {% include note/note_list.html %}
        {% elif file_type == "md" or file_type == "text" %}
            {% include note/editor/markdown.html %}
        {% elif file_type == "csv" %}
            {% include note/editor/csv_editor.html %}
        {% elif file_type == "gallery" %}
            {% include note/editor/gallery.html %}
        {% elif file_type == "list" %}
            {% include note/editor/list.html %}
        {% else %}
            {% include note/editor/post.html %}
        {% end %}
    </div>

    {% init prev_note = None %}
    {% init next_note = None %}
    {% if prev_note or next_note %}
        <div class="card">
            {% if prev_note %}
                <div class="col-md-6"><a href="/note/{{prev_note.id}}?is_iframe={{is_iframe}}">[上一篇]{{prev_note.name}}</a></div>
            {% else %}
                <div class="col-md-6">[上一篇]无</div>
            {% end %}

            {% if next_note %}
                <div class="col-md-6"><a class="float-right" href="/note/{{next_note.id}}?is_iframe={{is_iframe}}">[下一篇]{{next_note.name}}</a></div>
            {% end %}
        </div>
    {% end %}

    {# 评论功能 #}
    {% if file_type != "group" %}
        {% include note/comment.html %}
    {% end %}

    {# 分页 #}
    {% if show_pagination and "page" in globals() %}
    <div class="card">
        {% include mod_pagenation.html %}
    </div>
    {% end %}

<script type="text/javascript">
function rename(id, oldName) {
    var newName = prompt("新名称", oldName);
    console.log(newName);
    if (newName != "" && newName != null) {
        $.post("/note/rename", {id:id, name:newName}, function (resp) {
            var code = resp.code;
            if (code != "success") {
                alert(resp.message);
            } else {
                // $("#file-"+id).text(newName);
                window.location.reload();
            }
        })
    }
}

function remove(id, name, parentId) {
    var confirmed = confirm("确定删除'" + name + "'?");
    if (confirmed) {
        $.post("/note/remove", {id:id}, function (resp) {
            var code = resp.code;
            if (code != "success") {
                alert(resp.message);
            } else {
                if (parentId) {
                    window.location.href = "/note/view?id="+parentId;
                } else {
                    window.location.href = "/";
                }
            }
        })
    }
}

</script>

{% end %}

{% block aside %}
    {% include note/mod_aside.html %}
{% end %}
